package com.inspur.servlet;

import com.inspur.bean.Category;
import com.inspur.service.impl.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author：齐文勇
 * @Package：${PACKAGE_NAME}
 * @Project：ProductMS
 * @name：${NAME}
 * @Date：2024/11/27 15:10
 * @Filename：${NAME}
 */
@WebServlet(urlPatterns = "/CategoryUpdateByIdServlet")
public class CategoryUpdateByIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name = request.getParameter("name");
        String id = request.getParameter("id");

        Category category=new Category();
        category.setName(name);
        category.setId(id!=null && !"".equals(id)?Integer.parseInt(id):0);

        boolean b = new CategoryServiceImpl().updateById(category);

        response.sendRedirect("CategoryListServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }
}
